package com.controller;

import com.controller.reqdto.HeartReportParam;
import com.controller.reqdto.InstructParam;
import com.controller.reqdto.report.PcReportParam;
import com.controller.reqdto.report.SocketTestParam;
import com.controller.template.ResultHelper;
import com.controller.template.ResultInfo;
import com.service.PcService;
import com.util.WebsocketUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@Api(tags = "指令控制、PC信息上报模块")
@CrossOrigin
@RequestMapping("/instruct")
@Slf4j
public class InstructController extends ResultHelper {
    @Resource
    PcService pcService;
    /**
     * 指令下发
     *
     * @param instructParam
     * @return
     */
    @ApiOperation("指令下发")
    @PostMapping("/control")
    public ResultInfo heartReport(@RequestBody InstructParam instructParam) {
        pcService.control(instructParam);
        return successResultInfo("指令下发成功");
    }

    /**
     * 心跳上报
     *
     * @param pcReportParam
     * @return
     */
    @ApiOperation("pc数据上报")
    @PostMapping("/pcMsgReport")
    public ResultInfo heartReport(@RequestBody PcReportParam pcReportParam) {
        log.info("心跳上报参数：{}", pcReportParam);
        pcService.pcMsgReport(pcReportParam);
        return successResultInfo("心跳上报成功");

    }
    /**
     * socket消息测试
     *
     * @param socketTestParam
     * @return
     */
    @ApiOperation("socket消息测试")
    @PostMapping("/socketTest/")
    public ResultInfo socketTest(@RequestBody SocketTestParam socketTestParam) {
        WebsocketUtil.sendMessage(socketTestParam.getPcUniqueKey(),socketTestParam.getMsg());

        return successResultInfo("消息发送成功");

    }

    /**
     * socket消息测试
     *
     * @param
     * @return
     */
    @ApiOperation("socket连接信息获取")
    @GetMapping("/socketMsg/")
    public ResultInfo socketMsg() {
        List<String> allKeys = WebsocketUtil.getAllKeys();
        return successResultInfo(allKeys);

    }



}
